import 'package:unittest/unittest.dart';
import 'package:logging/logging.dart';
import 'node.dart';

final Logger logger = Logger.root;

void logConsole(LogRecord lrec) {
  print("${lrec.sequenceNumber} ${lrec.time} ${lrec.level} ${lrec.loggerName} ${lrec.message}");
}

void main() {
  logger.onRecord.listen(logConsole);

  test("testNodeSimple", testNodeSimple);
  test("testNodeWithPositionalFeatures", testNodeWithPositionalFeatures);
  test("testNodeWithNamedFeatures", testNodeWithNamedFeatures);
  test("testNode", testNode);
}

// -------------------------------------------------------------------------------------------------

void testNodeSimple() {
  final Node node = new Node.simple("simple");
}

void testNodeWithPositionalFeatures() {
  const N = 100;
  final Node node = new Node.simple("node");
  for (int i = 0; i < N; ++i) {
    node.appendChild(new Node.simple("s${i}"));
  }
}

void testNodeWithNamedFeatures() {
  const N = 100;
  final Node node = new Node.simple("node");
  for (int i = 0; i < N; ++i) {
    final Node nf = new Node.simple("f${i}");
    node.addNamedChild("f${i}", nf);
  }
}

void testNode() {
  final Node node = new Node.root()
      .addNamedChild(1, new Node.simple("Content for node #1")
          .addNamedChild("function", new Node.simple("fname")))
      .addNamedChild("feat1", new Node.simple("Label for node @feat1")
          .addNamedChild("sf1", new Node.simple("simple nest")))
      .addNamedChild("feat2", new Node.simple("a content"))
      .addNamedChild("tuple-test", new Node.simple("Tuple")
          .appendChild(new Node.simple("value1"))
          .appendChild(new Node.simple("value2"))
          .appendChild(new Node.simple("value3")))
      .addNamedChild("feat4", new Node.simple("b content"));
}